package com.weijianhuawen.wjblog.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weijianhuawen.wjblog.admin.convert.BlogSettingsConvert;
import com.weijianhuawen.wjblog.admin.mode.vo.setting.FindBlogSettingsRspVo;
import com.weijianhuawen.wjblog.admin.mode.vo.setting.UpdateBlogSettingsReqVo;
import com.weijianhuawen.wjblog.admin.service.AdminBlogSettingsService;
import com.weijianhuawen.wjblog.admin.service.AdminFileService;
import com.weijianhuawen.wjblog.common.domain.dos.BlogSettingsDo;
import com.weijianhuawen.wjblog.common.domain.mapper.BlogSettingsMapper;
import com.weijianhuawen.wjblog.common.enums.ResponseCodeEnum;
import com.weijianhuawen.wjblog.common.exception.BizException;
import com.weijianhuawen.wjblog.common.utils.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description:
 * @date: 2024-10-23 21:57
 */

@Service
@Slf4j
public class AdminBlogSettingsServiceImpl extends ServiceImpl<BlogSettingsMapper, BlogSettingsDo> implements AdminBlogSettingsService {
    @Autowired
    private BlogSettingsMapper blogSettingsMapper;
    @Override
    public Response updateBlogSettings(UpdateBlogSettingsReqVo vo) {
        //将vo转do
        BlogSettingsDo blogSettingsDo = BlogSettingsConvert.INSTANCE.convertVoToDo(vo);
        blogSettingsDo.setId(1L);
//        BlogSettingsDo blogSettingsDo = BlogSettingsDo.builder()
//                .id(1L)
//                .logo(vo.getLogo())
//                .author(vo.getAuthor())
//                .avatar(vo.getAvatar())
//                .giteeHome(vo.getGiteeHomepage())
//                .githubHome(vo.getGithubHomepage())
//                .zhihuHome(vo.getZhihuHomepage())
//                .csdnHome(vo.getCsdnHomepage())
//                .introduction(vo.getIntroduction())
//                .blogName(vo.getName())
//                .build();

        //更新数据
        saveOrUpdate(blogSettingsDo);
        return Response.success();
    }

    @Override
    public Response findDetail() {
        //查询id为1的记录
        BlogSettingsDo blogSettingsDo = blogSettingsMapper.selectById(1L);
        if (Objects.isNull(blogSettingsDo)) {
            throw new BizException(ResponseCodeEnum.BLOG_SETTING_ADMIN_USER_NOT_FIND);
        }

        // do to vo
        FindBlogSettingsRspVo vo = BlogSettingsConvert.INSTANCE.convertDoToVo(blogSettingsDo);
        System.out.println(blogSettingsDo.toString());
        System.out.println(vo.toString());
        //返回请求
        return Response.success(vo);
    }
}
